import Vue from 'vue'
import ViewUI from 'view-design'
import { router, initRouter } from './router/index'
import { appRouter } from './router/router'
import store from './store'
import App from './app.vue'
import 'view-design/dist/styles/iview.css'
import './styles/bootstrap.min.css'
import Viser from 'viser-vue'

// 自定义指令
import draggable from '@/derective/draggable.js'
Vue.directive('draggable', draggable)

// 右键菜单
import contentmenu from 'v-contextmenu'
import 'v-contextmenu/dist/index.css'
Vue.use(contentmenu)

// 引入请求库
import $ajax from './libs/ajax.js'
Vue.prototype.$ajax = $ajax

Vue.use(ViewUI)
Vue.use(Viser)

new Vue({
    el: '#app',
    router: router,
    store: store,
    render: h => h(App),
    data: {
        currentPageName: ''
    },
    mounted() {
        this.currentPageName = this.$route.name
        // 显示打开的页面的列表
        this.$store.commit('setOpenedList')
        this.$store.commit('initCachepage')
        // 权限菜单过滤相关
        this.$store.commit('updateMenulist')
    },
    created() {
        let tagsList = []
        appRouter.map((item) => {
            if (item.children.length <= 1) {
                tagsList.push(item.children[0])
            } else {
                tagsList.push(...item.children)
            }
        })
        this.$store.commit('setTagsList', tagsList)
    }
})